package com.dingreading.cloud.soms.service;

import com.dingreading.cloud.common.util.PageUtil;
import com.dingreading.cloud.soms.dto.CmServiceCountDto;
import com.dingreading.cloud.soms.dto.CmservicesDto;
import com.dingreading.cloud.soms.dto.LeftLessonDto;
import com.dingreading.cloud.soms.dto.SimpleCmserviceDto;
import com.dingreading.cloud.soms.entity.Cmservices;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 服务层。
 *
 * @author Administrator
 * @since 2023-11-22
 */
public interface CmservicesService extends IService<Cmservices> {

    Page<CmservicesDto> pageList(PageUtil pageUtil, String storeUid, String memberUid, String keyword);

    Page<CmservicesDto> storePage(
            PageUtil pageUtil, String storeUid, String keyword, String beginDate, String endDate,
            Integer status, Integer type, Integer gift
    );

    void dropByOrderCode(String storeUid, String memberUid, String orderCode);

    // 删除不要的且未开卡的基础服务
    void dropByOrderCodeAndUidNot(String storeUid, String memberUid, String orderCode, List<String> serviceUids);

    // 更新服务信息
    void updateList(String storeUid, String memberUid, String orderCode, String orderType, List<String> uids, String staffUid, String staffName);

    // 获取开卡、未开卡、暂停状态的服务列表
    List<CmservicesDto> dtoListByOrderCodeAndStatusIn(String storeUid, String memberUid, String orderCode);

    List<CmservicesDto> dtoListByOrderCodeOrRelationCode(String storeUid, String orderCode);

    // 获取开卡、未开卡、暂停状态的服务列表
    List<CmservicesDto> dtoListByOrderCodesAndStatusIn(String storeUid, List<String> orderCodes);

    List<SimpleCmserviceDto> simpleDtoListByOrderCodesAndStatusIn(String storeUid, List<String> orderCodes);

    CmservicesDto dtoByUid(String storeUid, String memberUid, String orderCode, String uid);

    Cmservices getByUid(String storeUid, String orderCode, String uid);

    boolean updateInfo(
            String storeUid, String orderCode, String serviceUid, String lastStaffUid, String lastStaffName,
            String staffUid, String staffFullName, String staffNickName,
            String staffPriPhone, String remarks
    );

    boolean setStatusV3(
            String storeUid, String orderCode, String serviceUid, String lastStaffUid, String fullName,
            Date beginDate, Date endDate, Date pauseDate, int status, String statusName
    );

    // 获取订单内已开卡的服务项目数
    boolean haveOpenCard(String orderCode);

    Map<String, LeftLessonDto> getLeftLessonCntV2(String storeUid, String projectUid, List<String> memberUids);

    // 按订单创建时间升序且赠送升序查可消耗的服务
    Cmservices getMemberConsumesService(String storeUid, String memberUid, String projectUid);

    // 按订单创建时间升序且赠送升序查可消耗的未开卡服务
    Cmservices getMemberConsumesNoCardService(String storeUid, String memberUid, String projectUid);

    // 消耗一次服务项目的剩余活动数量
    // 在定时器下加上注解，防止报错
    @Transactional(rollbackFor = Exception.class)
    boolean updateLeftLesson(String corpUid, String storeUid, String memberUid, String uid);

    // 更新订单的变更状态
    boolean updateChangeStatusByUidList(
            List<String> uidList, String memberUid, String orderCode, String staffUid, String staffName,
            String relationCode, Date changeDate, Integer changeStatus, String changeStatusName
    );

    // 删除时判断是否包括已开卡的服务
    boolean existOpenServices(String storeUid, String memberUid, String orderCode, List<String> serviceUids);

    boolean haveProjectUid(String storeUid, String projectUid);

    boolean haveProductUid(String storeUid, String productUid);

    List<Cmservices> listByStoreUidAndMemberUidAndUidIn(String storeUid, String memberUid, List<String> serviceUidList);

    // 获取会员可转移的服务
    List<CmservicesDto> getTransferServices(String storeUid, String memberUid);

    boolean updateStoreInfo(String storeUid, String memberUid, String toStoreUid, String toStoreName, List<String> uids);

    List<Cmservices> listByOrderCodeAndType(String orderCode, boolean editOrder);

    // 更新服务的服务总金额和单课次金额
    void updateAmount(String uid, double totalAmount, double unitAmount);

    List<CmservicesDto> exportList(
            String storeUid, String keyword, String beginDate, String endDate,
            Integer status, Integer type, Integer gift
    );

    List<Cmservices> listByOrderCodeAndChangStatusIsNullAndEnding(String storeUid, String memberUid, String orderCode);

    List<Cmservices> listByOrderCodeAndChangStatusIsNull(String storeUid, String memberUid, String orderCode);

    boolean setFinish(String storeUid, String orderCode, String uid, String endingRemark, String staffUid, String staffName);

    boolean setRecover(String storeUid, String orderCode, String uid, String staffUid, String staffName);

    Cmservices getMemberConsumesServiceV2(List<String> orderCodeListBy250699List, String storeUid, String memberUid, String projectUid);

    List<Cmservices> listByOrderCodeIn(List<String> orderCodeList);

    List<CmServiceCountDto> cmserviceCountList(String storeUid, List<String> orderCodeList);

    // 应续费人数（4次课内除6年级）
    List<CmServiceCountDto> shouldRenewList(String storeUid, String beginDate, String endDate);

    // 门店正价结课会员（含退费会员）
    List<CmServiceCountDto> endingList(String storeUid, String beginDate, String endDate);

    // 获取会员的推送服务剩余次数
    List<Cmservices> getPushCmservices(String corpUid, String storeUid, String projectUid, List<String> memberUidsForPush);

    boolean setStatusAndActivate(
            String storeUid, String orderCode, String serviceUid, String lastStaffUid, String fullName,
            Date beginDate, Date endDate, int status, String statusName,
            String mainSubjectUid, String mainSubjectName, String subjectUid, String subjectName,
            String stageUid, String stageName, Integer payType, Double activateAmount
    );

    List<String> getStudentsByTeacher(String corpUid, String storeUid, String uid);

    List<Cmservices> getByMemberUid(String memberUid);
}
